// CanvasText class - line element for scene - draws and manages text in the scene
CanvasText.prototype = new Shape();  
CanvasText.prototype.constructor=CanvasText;
function CanvasText(x, y){
	this.x = x;
	this.y = y;
	this.updateBoundary(this.x,this.y,0,0);
	
	this.text = "";
	this.updateBoundary = function(x,y,w,h){
		this.boundary = {x:x-1, y:y-(h*1.5)/2-1, w:w+2, h:h+2};
	}		
	
	this.setText = function(text){
		if(!this.scene)
			throw "The text cannot be set until the shape is added into a scene.";
			
		// set text
		this.text = text;
		
		// compute the text size
		var origFont = this.scene.context.font;
		this.scene.context.font = this.fontSize+" "+this.fontFamily;
		var textSize = this.scene.context.measureText(this.text);
		this.scene.context.font = origFont;
		
		// update the shape size, and the shape boundary
		this.w = textSize.width;
		// compute height
		this.h = this.fontSize*1.5;
		this.updateBoundary(this.x,this.y, this.w, this.h);
		//console.log(JSON.stringify(this.boundary));
	}
	
	// draw the text in the scene
	this.draw = function(ctx){
		//ctx.beginPath();	
		this.setFillStyles(ctx);
		this.setStrokeStyles(ctx);		
		ctx.font = this.fontSize+" "+this.fontFamily;
		ctx.fillText(this.text, this.x, this.y);
			
		//ctx.rect(this.boundary.x,this.boundary.y,this.boundary.w,this.boundary.h);
		//ctx.closePath();
		//this.fill=true;
		this.executeDraw(ctx);
		
	};
}
